import { platform } from '@/utils/platform'
export const usePayTool = () => {
  const payTool = (data: any) => {
    if (platform === 'mp-weixin') {
      wx.requestPayment({
        timeStamp: data.timeStamp, // 时间戳
        nonceStr: data.nonceStr, // 随机字符串
        package: data.package, // prepay_id
        signType: data.signType, // 签名算法MD5
        paySign: data.paySign, // 签名
        success(res) {
          const item: any = {
            name: '待付款',
          }
          if (res.errMsg === 'requestPayment:ok') {
            item.name = ''
          } else {
            item.name = '待付款'
          }
          uni.setStorageSync('orderStatus', JSON.stringify(item))
          uni.navigateTo({
            url: '/pages/shopping/allOrder',
          })
        },
        fail(res) {
          console.log(res)
          const item: any = {
            name: '待付款',
          }
          uni.setStorageSync('orderStatus', JSON.stringify(item))
          uni.navigateTo({
            url: '/pages/shopping/allOrder',
          })
        },
      })
    }
  }
  return { payTool }
}
